<?php

function assemble_register_user() {
$xml = '
<registeruser>
	<source>testapp</source>
	<details>
		<emailid>londonnode@gmail.com</emailid>
		<password>hello</password>
		<name>paddy</name>
		<address>1260, noida</address>
		<city>noida</city>
		<state>UP</state>
		<country>India</country>
		<zip>110011</zip>
		<phone>01143018553</phone>
		<dob>1981-12-12</dob>
		<imid>londonnode</imid>
		<imservice>gmail</imservice>
	</details>
</registeruser>';

return $xml;
}

function assemble_add_info() {
$xml = '
<addinfo>
   <source>web-browser</source>
   <emailid>hello.kr.dev1@gmail.com</emailid>
   <tokenid>88b9e057-4893-4c60-8f2a-e7566e841513</tokenid>
   <details>
      <info>program stable now</info>
      <media>0</media>
      <expirydate>2031-12-22</expirydate>
      <ttl>100</ttl>
   </details>
</addinfo>';

return $xml;
}

function assemble_add_info_recipients() {
$xml = '
<addinforecipients>
         <source>web-browser</source>
        <emailid>hello.kr.dev1@gmail.com</emailid>
         <tokenid>88b9e057-4893-4c60-8f2a-e7566e841513</tokenid>
         <infoid>50</infoid>
        <recipients>
				<recipient>
					<name>K-Nandan1</name>
					<phone>01143018553</phone>
					<emailid>k.n.a@gmail.com</emailid>
				</recipient>
            <recipient>
            </recipient>
        </recipients>
</addinforecipients>';

	return $xml;
}

function delete_info_recipient() {
$xml = '
<deleteinforecipient>
         <source>web-browser</source>
        <emailid>hello.kr.dev1@gmail.com</emailid>
        <tokenid>2f80a946-9ec8-4bfc-9308-e79eb92ec2aa</tokenid>
        <details>
                <infoid>13</infoid>
                <recipientid>27</recipientid>
        </details>
</deleteinforecipient>';

	return $xml;
}


function assemble_login() {
$xml = '
<login><source>testapp</source><details><emailid>hello.kr.dev1@gmail.com</emailid><password>hello</password></details></login>';

return $xml;
}

function assemble_fetch_user_data() {
$xml = '
<fetchuserdata>
        <source>app</source>
        <emailid>hello.kr.dev1@gmail.com</emailid>
        <tokenid>88b9e057-4893-4c60-8f2a-e7566e841513</tokenid>
</fetchuserdata>';

return $xml;
}

function assemble_add_recipient() {
$xml = '
<addrecipient>
	<source>app</source>
	<emailid>hello.kr.dev1@gmail.com</emailid>
	<tokenid>1d6eae7b-f0b2-4cc7-a04f-550947586853</tokenid>
	<details>
		<name>uuusjdfjdsa</name>
		<phone>9971295647</phone>
	</details>
</addrecipient>';

return $xml;
}

//		<phone>9971295647</phone>
//		<address>1260, sec 29, noida</address>
//		<relationship>brother</relationship>
function curl_request($url,  $postdata = false) //single custom cURL request.
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, TRUE); 
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);     

    curl_setopt($ch, CURLOPT_URL, $url);

    if ($postdata)
    {
        curl_setopt($ch, CURLOPT_POST, true);
			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, "$postdata");   
    }

    $response = curl_exec($ch);

    curl_close($ch);

    return $response;
}

//$url = 'http://localhost:9091/axis2/services/ima/registerUser';
$url = 'http://192.168.192.130:8080/axis2/services/ima/addrecipient';
//$xml = '
//<registeruser><source>testapp</source><details><emailid>nandan2@gmail.com</emailid><password>hello</password><name>paddy</name><address>1260, noida</address><city>noida</city><state>UP</state><country>India</country><zip>110011</zip><phone>01143018553</phone><dob>1981-12-12</dob><imid>kam3al.nandan</imid><imservice>gmail</imservice></details></registeruser>';

//$xml = '
//<confirmuserregistration><source>testapp</source><details><emailid>nandan5@gmail.com</emailid></details></confirmuserregistration>';

//$xml = '
//<addinforecipients>
//         <source>web-browser</source>
//        <emailid>kamal.nandan@gmail.com</emailid>
//         <tokenid>e91780bf-e4e7-4eb8-8584-3efd03d63565</tokenid>
//         <infoid>10</infoid>
//        <recipients>
//				<recipient>
//					<name>KN</name>
//					<emailid>knandan@gmail.com</emailid>
//				</recipient>
//				<recipient>
//					<name>Ramesh</name>
//					<emailid>rc@gmail.com</emailid>
//					<phone>01204294179</phone>
//					<address> Takshshila, I. P. Extension, Delhi </address>
//					<relationship> brother </relationship>
//				</recipient>
//        </recipients>
//</addinforecipients>';

//$xml = '
//<addinforecipients>
//        <source>web-browser</source>
//        <emailid>kamal.nandan@gmail.com</emailid>
//        <tokenid>e86bf04d-55c8-4ad4-8480-e08170cb6f32</tokenid>
//        <infoid>10</infoid>
//        <recipients>
//        </recipients>
//</addinforecipients>';

//$xml = '
//<login><source>testapp</source><details><emailid>kamal.nandan@gmail.com</emailid><password>hello</password></details></login>';
//

$xml = assemble_add_info();

$xml = assemble_add_info_recipients();

//$xml = delete_info_recipient();

$xml = assemble_login();
//$xml = assemble_register_user();
$xml = assemble_fetch_user_data();
$xml = assemble_add_recipient();

print_r("Request XML is:");
print_r($xml); 
$response = curl_request($url, $xml);

print_r ($response);
print_r("\n");
?>
